#include <allegro.h>
#include <stdlib.h>

int main(void){

    int x = 100, y = 100;
    int xdir = 10, ydir = 10;
    int red,green,blue,color;
    int radius = 50;

    allegro_init();
    install_keyboard();
    install_timer();
    srand(time(NULL));

    int ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);

    if(ret!=0){
        allegro_message(allegro_error);
        return 1;
    }

    textprintf_ex(screen,font ,0,0,15,-1,"FloodFill Program - %dx%d - Press ESC to quit.", SCREEN_W, SCREEN_H);

    while(!key[KEY_ESC]){
        x += xdir;
        if(x>SCREEN_W-radius){
            xdir = -10;
            radius = 10 + rand() % 40;
            x = SCREEN_W-radius;
        }
        if(x < radius){
            xdir = 10;
            radius = 10 + rand() % 40;
            x = radius;
        }

        y += ydir;
        if(y> SCREEN_H-radius){
            ydir = -10;
            radius = 10 + rand() % 40;
            y = SCREEN_H-radius;
        }
        if(y < radius+20){
            ydir = 10;
            radius = 10 + rand() % 40;
            y = radius+20;
        }

        red = rand() % 255;
        green = rand() % 255;
        blue = rand() % 255;
        color = makecol(red,green,blue);

        circle(screen, x,y,radius,color);
        floodfill(screen,x,y,color);
        rest(40);
        rectfill(screen,x-radius,y-radius,x+radius,y+radius,0);

        rest(100);
    }

    allegro_exit();
    return 0;

}
END_OF_MAIN()
